var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		binfo: [],
		money: 0,
		bset: false,
	},
	_onLoad: function (options) {
		var that = this
		$.get('businessht/withdraw',{},function(res){
			that.setData(res)
		})
	},
	moneyinput: function (e) {
		var usermoney = parseFloat(this.data.binfo.money);
		var money = parseFloat(e.detail.value);
		if (money < 0) {
			$.error('必须大于0');
		} else if (money > usermoney) {
			$.error('可提现余额不足');
			return {
				value: usermoney,
			}
		} else {
			this.setData({ money: money })
		}
	},
	formSubmit: function (e) {
		var that = this
		var usermoney = parseFloat(this.data.binfo.money);
		var withdrawmin = parseFloat(this.data.bset.withdrawmin);
		var formdata = e.detail.value;
		var money = parseFloat(formdata.money);
		var paytype = formdata.paytype;
		if (isNaN(money) || money <= 0) {
			$.error('提现金额必须大于0');
			return;
		}
		if (withdrawmin > 0 && money < withdrawmin) {
			$.error('提现金额必须大于¥' + withdrawmin);
			return;
		}
		if (money > usermoney) {
			$.error('余额不足');
			return;
		}
		if(paytype == '支付宝' && !this.data.binfo.aliaccount){
			$.alert('请先设置支付宝账号', function () {
				$.goto('txset');
			});
			return;
		}
		if(paytype == '银行卡' && (!this.data.binfo.bankname || !this.data.binfo.bankcarduser || !this.data.binfo.bankcardnum)){
			$.alert('请先设置完整银行卡信息', function () {
				$.goto('txset');
			});
			return;
		}
		$.post('businessht/withdraw', { money: money, paytype: paytype}, function (data) {
			if (data.status == 0) {
				$.error(data.msg);
				return;
			} else {
				$.success(data.msg);
				setTimeout(function () {
					$.goto('moneylog?st=2');
				}, 1000)
			}
		}, '提交中')
	}
}))